﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SY.WebApiTool.Tool;
using SY.WebApiTool.Interface;
using SY.WebApiTool.Model;
using Newtonsoft.Json;
using SY.WebApiTool.Model.Expand;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
        
            IWebApiTool materialTool = new MaterialTool("5a5c5fccb3d37e", "administrator", "888888","http://192.168.1.150");
            ((MaterialTool)materialTool).Materials = new List<Material> { new SY.WebApiTool.Model.Expand.MaterialAnecoo("TestApi1", "100", "100",thickness:5.5555M ),
            new SY.WebApiTool.Model.Expand.MaterialAnecoo("TestApi2", "100", "100",thickness:55.5555M )};
            materialTool.Validate();

            bool isEnd = false;

            while (!isEnd)
            {
                Console.WriteLine("请输入输入操作名称,或输入Y结束;/r/n");
                string Input = Console.ReadLine();
                MaterialJsonResult result = null;
                switch (Input.ToLower())
                {
                    case "save":
                        result = SaveResult(materialTool) as MaterialJsonResult;
                        break;
                    case "summit":
                        result = SummitResult(materialTool) as MaterialJsonResult;
                        break;
                    case "audit":
                        result = AuditResult(materialTool) as MaterialJsonResult;
                        break;
                    case "y":
                        isEnd = true;
                        break;
                }
                if(!isEnd)
                    Console.WriteLine(result?.Result.ResponseStatus.IsSuccess.ToString() ?? "无效的操作名");
                if (result != null)
                {
                    var a = MaterialTool.ResutlInfoReturn(result,(OperationType)Enum.Parse(typeof(OperationType),Input));
                    foreach (var item in a)
                    {
                        Console.Write($"序号{item.Index},成功{item.Succeed},编码{item.Number},名称{item.Name}");
                        Console.WriteLine();
                    }

                }
            }

            
            

        }


        static string returnString(Father father)
        {
            return father.Test();
        }

        private static IJsonResult SaveResult(IWebApiTool webApiTool)
        {
            return webApiTool.Save();
        }

        private static IJsonResult SummitResult(IWebApiTool webApiTool)
        {
            return webApiTool.Summit();
        }

        private static IJsonResult AuditResult(IWebApiTool webApiTool)
        {
            return webApiTool.Audit();
        }
    }

    public class Father {
        public virtual string Test() { return "this is father"; }
        

    }

    public class Son : Father
    {
        public override string Test()
        {
            return "this is son";
        }
    }

}
